package zjhr.com.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zjhr.com.mapper.ZjFactoryMapper;
import zjhr.com.pojo.EasyUIPageQuery;
import zjhr.com.pojo.ZjFactory;
import zjhr.com.pojo.ZjFactoryExample;
import zjhr.com.service.FactoryService;
import zjhr.com.utils.IDUtils;
@Service
public class FactoryServiceImpl implements FactoryService {
	@Autowired
	private ZjFactoryMapper factoryMapper;
	//添加公司信息
	@Override
	public void addFactory(ZjFactory factory) {
		factory.setId(IDUtils.genImageName());
		factoryMapper.insert(factory);
		

	}
	@Override
	public List<ZjFactory> selectIdAndName() {
		List<ZjFactory> list = factoryMapper.selectIdAndName();
		return list;
	}
	//根据id找企业信息
	@Override
	public ZjFactory findNameShort(String id) {
		ZjFactory factory = factoryMapper.selectByPrimaryKey(id);
		return factory;
	}
	//分页
	@Override
	public EasyUIPageQuery pageQuery(Integer page, Integer rows) {
		ZjFactoryExample example = new ZjFactoryExample();
		int total = factoryMapper.countByExample(example);
		Integer start = (page-1)*rows;
		List<ZjFactory> list = factoryMapper.selectListByPageQuery(start,rows);
		EasyUIPageQuery pageQuery = new EasyUIPageQuery(total, list);
		return pageQuery;
	}
	//修改信息
	@Override
	public void edit(ZjFactory factory) {
		factoryMapper.updateByPrimaryKey(factory);
		
	}
	//导入添加
	@Override
	public void addImport(List<ZjFactory> list) {
		/*factoryMapper*/
		for (ZjFactory zjFactory : list) {
			factoryMapper.saveOrUpdate(zjFactory);
		}
		
	}

}
